package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.annotation.OperationLog;
import com.mall.db.domain.Address;
import com.mall.db.service.AddressService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/ac")
public class AddressController extends BaseController<Address>{

    @Resource(name = "addressService")
    private AddressService as;

    @Override
    @OperationLog(value = "查询收件信息",type = 0)
    public Map<String,Object>find(Address address){
        PageHelper.startPage(address.getPage(),address.getLimit());
        QueryWrapper<Address>qw = new QueryWrapper<>();
        List<Address>list = as.list(qw);
        PageInfo<Address>page = new PageInfo<>(list,address.getPage());
        return this.findMap(page.getList(),page.getTotal());
    }

    @RequestMapping("/addressFind")
    @ResponseBody
    public Map<String,Object>addressFind(@PathVariable(value = "mid")int mid){
        List<Address>list = as.addressFind(mid);
        return this.findMap(list,list.size()>0?list.get(0).getCount():0);

    }
    @Override
    @OperationLog(value = "添加地址",type = 0)
    public Map<String,Object>add(Address address){
        boolean b = as.save(address);
        return this.iud("新增",b,address);
    }


}
